package com.ruoyi.web.controller.drug;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.drug.domain.DrugInventory;
import com.ruoyi.drug.service.IDrugInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 药物资源管理Controller
 * 
 * @author ruoyi
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/drug/inventory")
public class DrugInventoryController extends BaseController
{
    @Autowired
    private IDrugInventoryService drugInventoryService;

    /**
     * 查询药物资源管理列表
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugInventory drugInventory)
    {
        startPage();
        List<DrugInventory> list = drugInventoryService.selectDrugInventoryList(drugInventory);
        return getDataTable(list);
    }

    /**
     * 导出药物资源管理列表
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:export')")
    @Log(title = "药物资源管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugInventory drugInventory)
    {
        List<DrugInventory> list = drugInventoryService.selectDrugInventoryList(drugInventory);
        ExcelUtil<DrugInventory> util = new ExcelUtil<DrugInventory>(DrugInventory.class);
        util.exportExcel(response, list, "药物资源管理数据");
    }

    /**
     * 获取药物资源管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:query')")
    @GetMapping(value = "/{drugId}")
    public AjaxResult getInfo(@PathVariable("drugId") Long drugId)
    {
        return AjaxResult.success(drugInventoryService.selectDrugInventoryByDrugId(drugId));
    }

    /**
     * 新增药物资源管理
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:add')")
    @Log(title = "药物资源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugInventory drugInventory)
    {
        return toAjax(drugInventoryService.insertDrugInventory(drugInventory));
    }

    /**
     * 修改药物资源管理
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:edit')")
    @Log(title = "药物资源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugInventory drugInventory)
    {
        return toAjax(drugInventoryService.updateDrugInventory(drugInventory));
    }

    /**
     * 删除药物资源管理
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:remove')")
    @Log(title = "药物资源管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drugIds}")
    public AjaxResult remove(@PathVariable Long[] drugIds)
    {
        return toAjax(drugInventoryService.deleteDrugInventoryByDrugIds(drugIds));
    }
}
